package com.yang.service;

import com.yang.dao.GoodDao;
import com.yang.pojo.good;

import java.sql.SQLException;
import java.util.ArrayList;

public class GoodService {
    GoodDao goodDao = new GoodDao();
    //保存商品信息
    public int saveGood(String goodName,String goodImg,int goodMinPrice,int goodFifthPrice,int fkBrandId) throws SQLException {
        int goodId = goodDao.insertGood(goodName, goodImg, goodMinPrice, goodFifthPrice);
        int i = goodDao.insertGoodAndBrand(fkBrandId, goodId);
        if(i>0){
            return goodId;
        }
        return 0;

    }

    //根据品牌id查询商品信息
    public ArrayList<good> findGoodByBrandId(int brandId) throws SQLException {
        ArrayList<good> goods = goodDao.selectGoodByBrandId(brandId);
        return goods;
    }

    //保存商品与评估选项的关系
    public boolean saveGoodAndInfoDetail(int goodId,int infoDetailId,int price) throws SQLException {
        int i = goodDao.insertGoodAndInfoDetail(goodId, infoDetailId, price);
        return i>0;
    }
}
